package com.backstage.service.impl;

import com.backstage.dao.UserMapper;
import com.backstage.pojo.Goods;
import com.backstage.pojo.User;
import com.backstage.service.UserService;
import com.backstage.utils.PageBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jws.soap.SOAPBinding;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public User selectHasUserName(String name){
        return userMapper.selectUserName(name);
    }

    public int selectUserTotal(){
        return userMapper.selectUserTobal();
    }

    public int selectUpDataSignTime(User record){
        return userMapper.updateByPrimaryKeySelective(record);
    }

    public int selectInsertUser(User record){
        return userMapper.insert(record);
    }

    public User selectUserKey(Integer id){
        return userMapper.selectByPrimaryKey(id);
    }

    //获取用户列表，带搜索分页
    public PageBean<User> selectUserList(int pageNum, int pageSize, String itemName){

        PageBean<User> pageBean = new PageBean<User>();
        User users = new User();
        if(!"".equals(itemName)){
            users.setName(itemName);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<User> usersList = userMapper.selectUserList(users);
        PageInfo<User> goodsPageInfo = new PageInfo<User>(usersList);

        pageBean.setList(usersList);
        pageBean.setPageBeanObj(goodsPageInfo.getPageNum(),goodsPageInfo.getPageSize(),goodsPageInfo.getNextPage(),goodsPageInfo.getPrePage(),goodsPageInfo.getTotal(),goodsPageInfo.getPages());

        return pageBean;

    }

}
